﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Ccit.Utils;
using Ccit.OA.MsSystemDoc;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Ccit.OA.SystemDoc
{
    public partial class SystemDoc_docmanage_filedit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                ViewState["fileId"] = (null != Request.QueryString["fileId"]) ? Request.QueryString["fileId"].ToString() : "";
                ViewState["classType"] = (null != Request.QueryString["classType"]) ? Request.QueryString["classType"].ToString() : "0001";
                btnConfirm.Attributes.Add("onclick", "return doUpload()");
                inpage();
            }
        }

        private void inpage()
        {
            if (ViewState["fileId"].ToString() != "")
            {
                string sClassType, sFileId, sWhere;
                sFileId = ViewState["fileId"].ToString().Trim();
                sClassType = ViewState["classType"].ToString().Trim();

                hidfileId.Value = sFileId;

                SystemDocBLL bll = new SystemDocBLL();
                MsDocClass ms = new MsDocClass();
                ms.sysdocid = sFileId;
                ms = bll.GetDoc(ms);

                sWhere = " and DOC_B2_10 = " + ms.sysecond;
                List<MsSecondClass> msList = bll.GetMsSecondItem(sWhere);
                if (msList.Count != 0)
                {
                    lbType.Text = msList[0].Systypename;
                }
                tbTitle.Text = ms.sysdoctitle;
                txtNumbers.Value = ms.syscode;
                hlndownload.Text = ms.sysdoctitle;
                string encodeparam = string.Empty;
                encodeparam = Base64Lib.Encode("classType=" + sClassType + "&Field=" + sFileId);
                hlndownload.NavigateUrl = "System_docmanage_download.aspx?" + encodeparam;
                msList = null;
                ms = null;
                bll = null;
            }
            else
            {
                btnConfirm.Visible = false;
            }
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            string sMsg = string.Empty;
            string sFileName = string.Empty;

            string serAttach = string.Empty;
            if (doSave())
            {
                Response.Write("<script>alert('文件更新成功!');</script>");
            }
        }

        public bool doSave()
        {
            bool bFlag = false;
            SystemDocBLL bll = new SystemDocBLL();
            MsDocClass ms = new MsDocClass();
            ms.sysdocid = ViewState["fileId"].ToString();
            ms.syscode = txtNumbers.Value.Trim();
            ms.updatetime = System.DateTime.Now.ToString().Trim();
            ms.sysremarks = txtremark.Text.Trim();
            ms.sysdoctitle = tbTitle.Text.Trim();
            if (bll.UpdateDoc(ms) > -1)
            {
                bFlag = true;
            }
            bll = null;
            return bFlag;
        }
    }
}
